<import file="block/common.html" name="url" :tpl_cfg="['urlName'=>$title,'backList'=>'返回列表','aid'=>$aid??$image['aid']]"/>
<div class="layui-fluid">
    <div class="layui-form">

        <div class="layui-form-item">
            <label class="layui-form-label required">缩略图</label>
            <div class="layui-input-inline" style="width:520px;" id="photopre">
                <?php if(!empty($image['imgsrc'])){ ?>
                    <img src="<{$image['imgsrc']}>" width="240" height="180" >
                <?php } ?> 
            </div>
        </div>


        <?php if(SysRolCk("upload_upload")){ ?>
        <div class="layui-form-item">
            <label class="layui-form-label required"></label>
            <div class="layui-input-block" style="width:520px;">
                <input type="text" id="imageval" name="imgsrc" value="<{$image['imgsrc']??''}>" class="layui-input">
                <button type="button" class="layui-btn" id="thumimg">
                    <i class="layui-icon">&#xe67c;</i>上传图片
                </button>
                <tip>宽1100px</tip>
            </div>
        </div>
        <?php } ?>
        <div class="layui-form-item">
            <label class="layui-form-label required">图片描述</label>
            <div class="layui-input-block">
                <textarea name="info" class="layui-textarea" style="height: 260px;"><{$image['info']??''}></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
            <?php if(!empty($image)){  ?>
                <input type="hidden" name="id" value="<{$image['id']}>">
                <?php }  if(!empty($aid)){  ?>
                <input type="hidden" name="aid" value="<{$aid}>">
                <?php  } ?>
                <button class="layui-btn" lay-submit lay-filter="saveBtn"><i class="layui-icon">&#x1005;</i><?php echo lang('submit');?></button>
            </div>
        </div>
    </div>
</div>
<script>
    layui.define(function () {
        var form = layui.form,
            layer = layui.layer,
            upload = layui.upload,
            $ = layui.$;

        var uploadInst = upload.render({
            elem: '#thumimg' //绑定元素
            , url: '<{CAUrl("upload","upload")}>&up=img' //图片上传接口
            , size: 1000
            , accept: 'images'
            , acceptMime: 'image/*'
            //,acceptMime: 'image/jpg, image/png'
            , done: function (res) {
                if (res.status == 1) {
                    $('#imageval').val(res.result[0].src);
                    $('#photopre').html('<img src="'+res.result[0].src+'" width="240" height="180" >');
                    layer.msg(res.info);
                } else {
                    layer.msg(res.info);
                }
            }
            , error: function () {
                //请求异常回调
            }
        });

        form.render();

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.post('<{CAUrl("imageinfo",ROUTE["act"])}>', data.field, function (res) {
                if (res.status == 1) {
                    layer.msg(res.info, { icon: 1, time: 1000 }, function () {
                        <?php if(!empty($image)){ ?>
                            loadMain('<{CAUrl("imageinfo","index")}>&aid=<{$image["aid"]}>');  
                        <?php }  if(!empty($aid)){?>
                            loadMain('<{CAUrl("imageinfo","index")}>&aid=<{$aid}>');
                        <?php  } ?>
                    });
                } else {
                    layer.msg(res.info, { icon: 2, anim: 6, time: 5000 });
                }
            });
            return false;
        });

    });
</script>